home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Biomorph 0.77 / Biomorph src / trackcoords.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-16  |  2.5 KB  |  119 lines  |  [TEXT/ALFA]

  1. /***************************
  2. ** trackcoords.c
  3. **
  4. ** This source file contains TrackCoords(), which
  5. ** follows the mouse as it is dragged in the gMainWindow
  6. ** and updates the X & Y min/max image coords.
  7. ****************************/
  8.  
  9. #include <MacHeaders>
  10. #include <stdio.h>
  11. #include "constants.h"
  12. #include "globals.h"
  13.  
  14. void TrackCoords(Point start)
  15. {
  16.     EventRecord theEvent;
  17.     Handle    h;
  18.     MathType xgap, ygap, mtemp;
  19. static Point end2;
  20.     Point end;
  21.     Rect box;
  22. static Rect selRect;    // selection rectangle
  23.     Str255    s;
  24.     int xmin, xmax, ymin, ymax, iType;
  25.     
  26.     SetPort(gMainWindow);
  27.     PenPat(black);
  28.     PenMode(patXor);
  29.     
  30.     GlobalToLocal(&start);
  31.         
  32.     xgap = (gXmax - gXmin) / (MathType)(gMainWindow->portRect.right -1);
  33.     ygap = (gYmax - gYmin) / (MathType)(gMainWindow->portRect.bottom -1);
  34.  
  35.     while ( Button() )
  36.     {
  37.         SetPort(gMainWindow);
  38.         GetMouse( &end);    // local coords already
  39.         
  40.         if ( (end2.h == end.h) &&
  41.             (end2.v == end.v) )  // same point, so skip
  42.         {
  43.             (void)WaitNextEvent( everyEvent, &theEvent, 0, NULL);
  44.             continue;
  45.         }
  46.         else                // different points, so do calcs
  47.             end2 = end;
  48.             
  49.         if (start.h < end.h)    // set x min and max
  50.         {
  51.             xmin = start.h;
  52.             xmax = end.h;
  53.         }
  54.         else
  55.         {
  56.             xmin = end.h;
  57.             xmax = start.h;
  58.         }
  59.         
  60.         if ( start.v < end.v)    // set y min and max
  61.         {
  62.             ymin = start.v;
  63.             ymax = end.v;
  64.         }
  65.         else
  66.         {
  67.             ymin = end.v;
  68.             ymax = start.v;
  69.         }
  70.         
  71.         FrameRect( &selRect);
  72.         selRect.left =xmin;
  73.         selRect.right=xmax+1;
  74.         selRect.top = ymin;
  75.         selRect.bottom = ymax+1;
  76.         FrameRect( &selRect);
  77.         
  78.         Print(NULL);    // Clears the message window
  79.         NumToString((long)end.h, s);
  80.         PtoCstr(s);
  81.         Print( (char*)s);
  82.         NumToString((long)end.v, s);
  83.         PtoCstr(s);
  84.         Print( (char*)s);
  85.         
  86.         // we now have x/y min/max values.
  87.         // Convert pixel values to coordinate values.
  88.         
  89.         mtemp = xgap * (MathType)xmin + gXmin;
  90.         sprintf( (char*)s, kMathFormat, mtemp);
  91.         CtoPstr(s);
  92.         GetDItem( gControlDialog, kETXMin, &iType, &h, &box);
  93.         SetIText( h, s);
  94.         
  95.         mtemp = gXmin +  xgap * (MathType)xmax;
  96.         sprintf( (char*)s, kMathFormat, mtemp);
  97.         CtoPstr(s);
  98.         GetDItem( gControlDialog, kETXMax, &iType, &h, &box);
  99.         SetIText( h, s);
  100.         
  101.         mtemp = gYmin +  ygap * (MathType)ymin;
  102.         sprintf( (char*)s, kMathFormat, mtemp);
  103.         CtoPstr(s);
  104.         GetDItem( gControlDialog, kETYMin, &iType, &h, &box);
  105.         SetIText( h, s);
  106.         
  107.         mtemp = gYmin +  ygap * (MathType)ymax;
  108.         sprintf( (char*)s, kMathFormat, mtemp);
  109.         CtoPstr(s);
  110.         GetDItem( gControlDialog, kETYMax, &iType, &h, &box);
  111.         SetIText( h, s);
  112.         
  113.     } // while
  114.     return;
  115.     
  116. } // TrackCoords()
  117.  
  118.  
  119.